package ro.prjmanager.core.context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * ApplicationContextFactory.java Copyright (c) 2009 Teamnet. All Rights Reserved. This source file
 * may not be copied, modified or redistributed, in whole or in part, in any form or for any reason,
 * without the express written consent of Teamnet.
 */
public class ApplicationContextFactory {

    public static WebContext get()
    {
        if (builder == null)
        {
            return null;
        }

        return builder.get();
    }


    public static void setWebContextBuilder(WebContextBuilder builder)
    {
        ApplicationContextFactory.builder = builder;
    }

    /**
     * The WebContextBuilder from which we will get WebContext objects
     */
    private static WebContextBuilder builder;


    public interface WebContextBuilder
    {
        /**
         * Make the current thread know what the current request is.
         * This method is only for use internally to DWR.
         * @param request The incoming http request
         * @param response The outgoing http reply
         * @see #unset()
         */
        void set(HttpServletRequest request, HttpServletResponse response);

        /**
         * @return The WebContext that is associated with this thread
         */
        WebContext get();

        void unset();
    }

}
